/*
Package service
@Time : 2022/12/20 22:42
@Author : 董胜烨
@File : employ
@Software: GoLand
@note:
*/
package service

import (
	"employee/model"
	"fmt"
)

type Employee struct {
	ID          int64  `json:"id"`
	BirthDate   string `json:"birth_date"`
	Department  string `json:"department"`
	Gender      string `json:"gender"`
	HireDate    string `json:"hire_date"`
	IDNumber    string `json:"id_number"`
	Name        string `json:"name"`
	SalaryDaily string `json:"salary_daily"`
}

func (e *Employee) Insert() bool {
	sqlStr := "INSERT INTO employee ( name, gender, hire_date, birth_date, id_number, department,salary_daily) VALUES (?,?,?,?,?,?,?)"
	insertId := model.Insert(sqlStr, e.Name, e.Gender, e.HireDate, e.BirthDate, e.IDNumber, e.Department, e.SalaryDaily)
	if insertId == 0 {
		return false
	}
	e.ID = insertId
	return true
}

func (e Employee) Update() bool {
	sqlStr := "UPDATE employee SET name=?,gender=?,hire_date=?,birth_date=?,id_number=?,department=?,salary_daily=? WHERE id=?"
	return model.Update(sqlStr, e.Name, e.Gender, e.HireDate, e.BirthDate, e.IDNumber, e.Department, e.SalaryDaily, e.ID)
}
func (e Employee) Delete() bool {
	sqlStr := "DELETE FROM employee WHERE id=?"
	return model.Delete(sqlStr, e.ID)
}
func (e Employee) QueryAll() []map[string]string {
	sqlStr := "SELECT * FROM employee"
	res := model.QueryAll(sqlStr)
	if res != nil {
		return res
	}
	return nil
}
func (e Employee) QueryOne() []map[string]string {
	sqlStr := fmt.Sprintf("SELECT * FROM employee WHERE id='%d'", e.ID)
	res := model.QueryAll(sqlStr)
	if res != nil {
		return res
	}
	return nil
}
